package com.example.perpetualcalendar.ui.fragment.history;

import androidx.annotation.NonNull;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;

import com.example.perpetualcalendar.data.network.AppSchedulerProvider;
import com.example.perpetualcalendar.domain.entity.History;
import com.example.perpetualcalendar.domain.entity.Joke;
import com.example.perpetualcalendar.domain.usecase.HistoryUseCase;
import com.example.perpetualcalendar.viewModel.BaseViewModel;

import java.util.List;

import io.reactivex.observers.DisposableObserver;

public class HistoryViewModel extends BaseViewModel<HistoryUseCase> {

    private MutableLiveData<List<History.ResultDTO>> mResultDTO;

    public HistoryViewModel() {
        mResultDTO = new MutableLiveData<>();
        history();
    }

    public LiveData<List<History.ResultDTO>> getResultDTO() {
        return mResultDTO;
    }
    @NonNull
    @Override
    protected HistoryUseCase setUseCase() {
        return new HistoryUseCase(AppSchedulerProvider.getInstance(), new HistoryRepository());
    }

    public void history() {
        assert useCase != null;
        useCase.execute(new DisposableObserver<History>() {
            @Override
            public void onNext(History history) {
                if(history!=null&&history.getResult()!=null){
                    mResultDTO.postValue(history.getResult());
                }
            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onComplete() {

            }
        },useCase.historyApi());
    }
}